$().ready(function () {
// 在键盘按下并释放及提交后验证提交表单
    $("#registerForm").validate({
        errorElement: 'span',
        errorPlacement: function (error, element) {
            error.appendTo(element.prev());
        },
        rules: {
            username: {
                required: true,
                minlength: 3
            },
            password: {
                required: true,
                minlength: 8,
                maxlength: 16
            },
            confirmpwd: {
                required: true,
                minlength: 8,
                equalTo: "#password"
            },
            email: {
                required: true,
                email: true
            },
            phone: {
                required: true,
                minlength: 11,
                maxlength: 11
            },
            vcode: {
                required: true
            }
        },
        messages: {
            username: {
                required: "请输入用户名",
                minlength: "昵称至少为三个字符"
            },
            password: {
                required: "请输入密码",
                minlength: "密码长度不能小于 8 个字符",
                maxlength: "密码长度最多为 16 个字符"
            },
            confirmpwd: {
                required: "请输入密码",
                minlength: "密码长度不能小于 8 个字符",
                equalTo: "两次密码输入不一致"
            },
            email: "请输入一个正确的邮箱",
            phone: {
                required: "请输入手机号",
                minlength: "手机号格式不正确",
                maxlength: "手机号格式不正确"
            },
            vcode: {
                required: "请输入验证码"
            }
        }
    });
    $("#userLoginForm").validate({
        errorElement: 'span',
        errorPlacement: function (error, element) {
            error.appendTo(element.prev());
        },
        rules: {
            account: {
                required: true
            },
            password: {
                required: true,
                minlength: 8,
                maxlength: 16
            },
            vcode: {
                required: true
            }
        },
        messages: {
            account: {
                required: "请输入账号"
            },
            password: {
                required: "请输入密码",
                minlength: "密码长度不能小于 8 个字符",
                maxlength: "密码长度最多为 16 个字符"
            },
            vcode: {
                required: "请输入验证码"
            }
        }
    });
    $("#adminLoginForm").validate({
        errorElement: 'span',
        errorPlacement: function (error, element) {
            error.appendTo(element.prev());
        },
        rules: {
            username: {
                required: true
            },
            password: {
                required: true,
                minlength: 5,
                maxlength: 16
            },
            code: {
                required: true
            }
        },
        messages: {
            username: {
                required: "请输入账号"
            },
            password: {
                required: "请输入密码",
                minlength: "密码长度不能小于 5 个字符",
                maxlength: "密码长度最多为 16 个字符"
            },
            code: {
                required: "请输入验证码"
            }
        }
    });
    $("#editPasswordForm").validate({
        errorElement: 'span',
        errorPlacement: function (error, element) {
            error.appendTo(element.prev());
        },
        rules: {
            oldPassword: {
                required: true,
                minlength: 8,
                maxlength: 16
            },
            newPassword: {
                required: true,
                minlength: 8,
                maxlength: 16
            }
        },
        messages: {
            oldPassword: {
                required: "请输入密码",
                minlength: "密码长度不能小于 8 个字符",
                maxlength: "密码长度最多为 16 个字符"
            },
            newPassword: {
                required: "请输入密码",
                minlength: "密码长度不能小于 8 个字符",
                maxlength: "密码长度最多为 16 个字符"
            }
        }
    });
    $("#addBookInfoForm").validate({
        errorElement: 'span',
        errorPlacement: function (error, element) {
            error.appendTo(element.prev());
        },
        rules: {
            name: {
                required: true
            },
            author: {
                required: true
            },
            publish: {
                required: true
            },
            ISBN: {
                required: true
            },
            publish_time: {
                required: true
            },
            detail: {
                required: true
            },
            author_detail: {
                required: true
            },
            context: {
                required: true
            },
            price: {
                required: true
            },
            cover: {
                required: true
            }
        },
        messages: {
            name: {
                required: "请输入图书名称"
            },
            author: {
                required: "请输入作者"
            },
            publish: {
                required: "请输入图书出版社"
            },
            ISBN: {
                required: "请输入ISBN"
            },
            publish_time: {
                required: "请输入出版时间"
            },
            detail: {
                required: "请输入图书简介"
            },
            author_detail: {
                required: "请输入作者简介"
            },
            context: {
                required: "请输入图书目录"
            },
            price: {
                required: "请输入价格"
            },
            cover: {
                required: "请选择封面"
            }
        }
    });
});
